﻿/**
 *       Project: ServerLib
 *     Copyright: Copyright (C) 2008, Rob Kennedy
 *   Create Date: 2008-07-14 10:16 PM
 * Modified Date: 2008-07-14 10:16 PM    RK  Added comments
 *      Comments: Ignore SA1633.
 *      
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace ServerLib.Network.Dns
{
    using System;

    /// --------------------------------------------------------------------
    /// Project	 : ServerLib
    /// Class	 : MXRecord
    /// Inherits : None.
    /// --------------------------------------------------------------------
    /// <summary>
    /// A compairable class to hold a Dns MX record data
    /// </summary>
    /// <authorname>Rob Kennedy</authorname>
    /// <remarks></remarks>
    /// --------------------------------------------------------------------
    public class MXRecord : IComparable
    {
        #region Private Properties

        /// <summary>Contains the MX server host domain name</summary>
        private string hostName;

        /// <summary>Contains the MX server preference order number</summary>
        private int preferenceIndex;

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the MX host domain name 
        /// </summary>
        public string HostName
        {
            get
            {
                return this.hostName;
            }

            set
            {
                this.hostName = value;
            }
        }
        
        /// <summary>
        /// Gets or sets the preference index of the MX host record.
        /// </summary>
        public int Preference
        {
            get
            {
                return this.preferenceIndex;
            }

            set
            {
                this.preferenceIndex = value;
            }
        }
        
        #endregion

        #region Public Methods
        
        /// <summary>
        /// Builds a display string using the MX Host name and order preference
        /// </summary>
        /// <returns>A display string containing the MX hostname and preference</returns>
        public override string ToString()
        {
            return String.Format("{0} [{1}]", this.HostName, this.Preference);
        }

        /// <summary>
        /// Used to sort a collection of MXRecord objects in a collection
        /// </summary>
        /// <param name="obj">The MXHost object to compair preference with</param>
        /// <returns>Returns a positive or zero value depending on preference order</returns>
        public int CompareTo(object obj)
        {
            if (obj is MXRecord)
            {
                MXRecord temp = (MXRecord)obj;
                return this.Preference.CompareTo(temp.Preference);
            }
            else
            {
                throw new Exception("Object is not an MX record");
            }
        }

        #endregion
    }
}
